package com.majun.listener;

import com.alibaba.fastjson.JSON;
import com.majun.bean.SysUserDto;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

/**
 * 监听消费同步批量发送的消息。
 *
 * TIPS: 指定 @RocketMQMessageListener 的属性 consumeMode = ConsumeMode.ORDERLY
 * 可以在消费消息时保证消费顺序，与生产消息集合时添加到集合中的顺序一致
 * 代价是只会创建一个消费者线程消费消息，效率偏低
 *
 * @author zy
 * @date 2020/6/16
 * @since 1.0.0
 */
@Slf4j
@Component
@RocketMQMessageListener(consumerGroup = "syncs-consumer", topic = "sync-messages")
public class SyncListMessageListener implements RocketMQListener<SysUserDto> {
    @Override
    public void onMessage(SysUserDto sysUserDto) {
        log.info("消费到了同步批量消息之: message = {}", JSON.toJSONString(sysUserDto));
    }
}
